package com.shhm.business.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.PageDTO;
import com.shhm.business.dto.request.EvaluationReq;
import com.shhm.business.dto.response.EvaluationResp;
import com.shhm.business.mapper.EvaluationMapper;
import com.shhm.business.service.EvaluationService;
import com.shhm.common.dto.request.RequestList;
import com.shhm.common.dto.response.AjaxResultPlus;
import com.shhm.common.dto.security.SecurityUser;
import com.shhm.common.entity.common.EvaluationEntity;
import com.shhm.common.utils.MybatisPlusUtil;
import com.shhm.common.utils.ResponseUtil;
import jakarta.annotation.Resource;
import org.apache.ibatis.annotations.Param;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @description: TODO 
 * @author JackZ
 * @date 2025/9/22 下午7:48
 * @version 1.0
 */
@Service
public class EvaluationServiceImpl implements EvaluationService {
    @Resource
    private  EvaluationMapper evaluationMapper;

    @Override
    public AjaxResultPlus pageList(Integer pageNum, Integer pageSize, Integer isPage) {
        PageDTO<EvaluationEntity> list = evaluationMapper.selectPage(new PageDTO<>(pageNum, pageSize), null);
        return AjaxResultPlus.custom(200, false)
                .put("data",list);
//                .put("operateStr","*");
//        return null;
    }

    @Override
    public AjaxResultPlus pageSearchList(Integer pageNum, Integer pageSize, Integer isPage, EvaluationReq entity) {
        AjaxResultPlus res = AjaxResultPlus.custom(200, false);
        if (isPage == 0)
            return res.put("data", evaluationMapper.selectDetail(entity));
        else{
            PageDTO<EvaluationEntity> list = evaluationMapper.selectDetailWithPage(new PageDTO<>(pageNum, pageSize), entity);
            res.put("data",list);
        }
        return res;
    }

    @Override
    public AjaxResultPlus add(EvaluationEntity entity) {
        entity.createLocalDateTime();
        SecurityUser info = (SecurityUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        entity.setUserId(info.getUserId());
        return ResponseUtil.sqlExeIsSuccess(evaluationMapper.insert(entity),"发布失败!");
    }

    @Override
    public AjaxResultPlus update(EvaluationEntity entity) {
        return ResponseUtil.sqlExeIsSuccess(evaluationMapper.updateById(entity));
    }

    @Override
    public AjaxResultPlus delete(RequestList ids) {
        List<Object> list = ids.getList();
        return ResponseUtil.sqlExeIsSuccess(evaluationMapper.deleteByIds(list));
    }
}
